﻿using System.IO;
using System.Threading.Tasks;
using Fluid;
using Fluid.Values;

namespace ZYing.LiquidThemeEngine.Filters
{
    public static class UrlFilters
    {
        public static ValueTask<FluidValue> AssetUrlAsync(FluidValue input, FilterArguments arguments, TemplateContext ctx)
        {
            var context = (LiquidThemeTemplateContext)ctx;
            var options = context.LiquidThemeEngineOptions;
            var formatter = options.AssetUrlFormatter;
            var file = input.ToStringValue();
            var version = context.GetFileVersion(Helper.CombinePath(Constants.Directories.Assets, file));
            var url = formatter(context.Theme, file, version);
            return StringValue.Create(url);
        }
    }
}